<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>11-原型重写</title>
</head>

<body>
    <script>
        function Person() {

        }
        function Animal() {

        }
        let person = new Person();
        let animal = new Animal();

        console.log(person.__proto__ === Person.prototype); // true  
        console.log(animal.__proto__ === Animal.prototype); //true
        console.log(Person.prototype);
        Person.prototype = {
            constructor:Person,
            "name": "Mike",
            sayName: function () {
                console.log(this.name);
            }
        }
        console.dir( Person.prototype.constructor);
        Animal.prototype.name = 'animal';
        Animal.prototype.sayName = function () {
            console.log(this.name);
        }
        console.log(person.__proto__ === Person.prototype); // false
        console.log(person.__proto__.constructor === Person.prototype.constructor); // true


        console.log(animal.__proto__ === Animal.prototype); //true
        person.sayName();  // error person.sayName is not a function
        animal.sayName();   // animal

    // https://blog.csdn.net/chengQunBin/article/details/78910943

        /*
            在重写原型对象的时候，
            Person.prototype 会创建一个新的原型对象，
            而 person.__proto__ 仍然指向原来的那个旧的原型对象
        */

    </script>
</body>

</html>